﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Write.API.Applications.Login;
using MediatR;

namespace ManagoMes.Read.API.Applications.ProductionScheduling
{
    public class WorkStationHtmlhandler : IRequestHandler<WorkStationHtmlCommond, ResultsDTO<WorkStationSto>>
    {

        private readonly IBateRepository<WorkStationSto> _WorkStation;

        private readonly Logincommonality _Logincommonality;

        public WorkStationHtmlhandler(IBateRepository<WorkStationSto> workStation, Logincommonality logincommonality)
        {
            _WorkStation = workStation;
            _Logincommonality = logincommonality;
        }

        public async Task<ResultsDTO<WorkStationSto>> Handle(WorkStationHtmlCommond request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new ResultsDTO<WorkStationSto>() { Code = 0 };

                var Emptey = new WorkStationSto();


                var str = "select * from workstation join workshop on workstation.workshopid = workshop.workshopid join processk on workstation.processid =processk.processid";

                DapperHelper dapperHelper = new DapperHelper();
                var putdata = _WorkStation.GetAll(str, Emptey, dapperHelper.MangoMesRead).ToList();


                if(!string.IsNullOrEmpty(request.GEtnumber) )
                {
                    putdata = putdata.Where(x => x.WorkStations == request.GEtnumber).ToList();
                }
                if(request.processid!=0)
                {
                    putdata = putdata.Where(x => x.processid == request.processid).ToList();
                }
                if(request.workshopid!=0)
                {
                    putdata = putdata.Where(x => x.workshopid == request.workshopid).ToList();
                }
                list.Data = putdata;

                var OperatorName = "123";
                var OperatorTime = DateTime.Now.ToString();
                var PerformOperation = "工作站显示";
                _Logincommonality.Loginaddget(OperatorName, OperatorTime, PerformOperation);

                return list;
            }
            catch (Exception)
            {

                throw;
            }

        }

    


    }
}
